package com.projectzqjz.parttimework.adapter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.projectzqjz.parttimework.R;
import com.projectzqjz.parttimework.entity.PartWorkEntity;
import com.projectzqjz.parttimework.ui.activity.PartWorkActivity;

import java.util.List;

import static com.projectzqjz.parttimework.base.Constant.ADD_WORK;
import static com.projectzqjz.parttimework.base.Constant.EDITOR_WORK;

public class PartWorkAdapter extends BaseQuickAdapter<PartWorkEntity, BaseViewHolder> {
    private Activity activity;

    public PartWorkAdapter(Activity activity, List<PartWorkEntity> newsList) {
        super(R.layout.item_work_experience, newsList);
        this.activity = activity;
    }

    @Override
    protected void convert(BaseViewHolder helper, PartWorkEntity item) {
        View view = helper.getView(R.id.ll_add);
        if (helper.getPosition() == 0) {
            view.setVisibility(View.VISIBLE);
        } else {
            view.setVisibility(View.GONE);
        }
        ((TextView) helper.getView(R.id.tv_company)).setText(item.getCompany_name());
        ((TextView) helper.getView(R.id.tv_time)).setText(item.getTime());
        ((TextView) helper.getView(R.id.tv_content)).setText(item.getContent());
        ((TextView) helper.getView(R.id.tv_job)).setText(item.getJob());
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {//添加工作经历
                activity.startActivityForResult(new Intent(activity, PartWorkActivity.class).putExtra("state", "add")
                        , ADD_WORK);
            }
        });
        helper.getView(R.id.iv_editor).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {//编辑简历
                Intent intent = new Intent(activity, PartWorkActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("company_name", item.getCompany_name());
                bundle.putString("content", item.getContent());
                bundle.putString("job", item.getJob());
                bundle.putString("time", item.getTime());
                bundle.putString("state", "editor");
                bundle.putString("position", helper.getPosition() + "");
                intent.putExtras(bundle);
                activity.startActivityForResult(intent, EDITOR_WORK);
            }
        });
    }
}
